<template>
  <div class="contact-container">
    <div class="user">
      <van-image
        width="80px"
        height="80px"
        fit="cover"
        :src="user.avatar"
        radius="8"
        class="avatar"
      />
      <div class="info">
        <div class="name-wrapper">
          <span class="name">{{user.name}}</span>
          <span class="gender"><svg-icon :icon="genderIcon" /></span>
        </div>
        <div class="id small-text">ID:{{userId}}</div>
        <div class="username small-text">用户名:{{user.username}}</div>
      </div>
    </div>
    <van-cell-group>
      <van-cell title="电话" :value="user.phone" is-link />
    </van-cell-group>
    <div class="button-group">
      <div class="button" @click="sendText"><van-icon class="icon" name="chat-o" />发信息</div>
      <van-divider />
      <div class="button" @click="videoCall"><van-icon class="icon" name="video-o" />视频通话</div>
    </div>
  </div>
</template>

<script>
import { mapActions } from 'vuex'
import globalEvent from '@/utils/event'
export default {
  name: 'ContactInfo',
  data() {
    return {
      user: {
        name: '',
        username: '',
        gender: 0,
        phone: '',
        avatar: ''
      }
    }
  },
  computed: {
    userId() {
      return this.$route.params.id
    },
    genderIcon() {
      return this.user.gender ? 'male' : 'female'
    }
  },
  mounted() {
  },
  created() {
    this.initContactData()
  },
  methods: {
    ...mapActions({ getContactInfo: 'contact/getContactInfo' }),
    async initContactData() {
      const info = await this.getContactInfo(this.userId)
      const { avatar, name, gender, phone, username } = info
      this.user.avatar = avatar
      this.user.name = name
      this.user.gender = gender
      this.user.phone = phone
      this.user.username = username
    },
    sendText() {
      this.$router.push({
        name: 'ChatInfo',
        params: { id: this.userId }
      })
    },
    videoCall() {
      globalEvent.emit('videoCall', this.userId)
    }
  }
}
</script>

<style lang="scss" scoped>
  .contact-container{
    padding-top: $nav-bar-height ;
    background-color: #EEEEEE;
    .user{
      background-color: #fff;
      display: flex;
      padding:$padding-side;
      .avatar{
        margin-right: $padding-side;
      }
      .info{
        flex: 1;
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        .name-wrapper{
          display: flex;
          font-size: $font-size-xlg;
          .name{
            flex: 1;
            font-weight: bold;
          }
        }
        .small-text{
          font-size: $font-size-sm;
          color: $gray-7;
        }
      }
    }
    .button-group{
      margin-top: $padding-side;
      background-color: #fff;
      .button{
        text-align: center;
        font-size: $font-size-lg;
        color: $blue;
        line-height: 36px;
        .icon{
          vertical-align: middle;
          margin-right: $padding-side;
        }
      }
      .van-divider{
        margin: 0;
      }
    }
  }
</style>
